//
//  AppDelegate.m
//  JXProgram
//
//  Created by 张吉旭 on 2017/10/27.
//  Copyright © 2017年 amplity. All rights reserved.
//

#import "AppDelegate.h"
//#import "PushManager.h"      // 适配iPhone5暂时注释(需添加ThirdManager文件夹 Src文件夹里面)
//#import "PushViewManager.h"  // 适配iPhone5暂时注释
//#import "ThirdLoginShareVerifyManager.h"  // 适配iPhone5暂时注释
#import "BasicNavigationController.h"
#import "LoginVC.h"
#import "TYFPSLabel.h"
#import "TabBarController.h"
#import "IQKeyboardManager.h"

@implementation AppDelegate

+ (AppDelegate *)appDelegate
{
    AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    return delegate;
}


+ (void)showMain
{
    TabBarController *tabBarController = [[TabBarController alloc] init];
    [AppDelegate appDelegate].mainTab = tabBarController;
    [AppDelegate appDelegate].window.rootViewController = [AppDelegate appDelegate].mainTab;
    
//    HomeVC *homeVC = [[HomeVC alloc] init];
//    BasicNavigationController *homeNav =[[BasicNavigationController alloc] initWithRootViewController:homeVC];
//    [AppDelegate appDelegate].window.rootViewController = homeNav;
}

+ (void)showLogin
{
    
    LoginVC *loginVC = [[LoginVC alloc] init];
    BasicNavigationController *loginNav =[[BasicNavigationController alloc] initWithRootViewController:loginVC];
    
    [AppDelegate appDelegate].window.rootViewController = loginNav;
    
}


+ (MBProgressHUD *)showHUDWithView:(UIView *)view
{
    return [self showHUDViewWithView:[AppDelegate appDelegate].window];
    
}

+ (MBProgressHUD *)showHUDViewWithView:(UIView *)view
{
    NSMutableArray *images = [[NSMutableArray alloc] init];
    for(int i=0;i<4; i++){
        [images addObject:[UIImage imageNamed:[NSString stringWithFormat:@"蚂蚁加载动画%d",i]]];
    }
    
    UIImageView *animationImageView = [[UIImageView alloc] init];
    animationImageView.frame = CGRectMake(0, 0, 110, 110);
    animationImageView.animationImages = images;
    animationImageView.animationDuration = 0.6;//设置动画时间
    animationImageView.animationRepeatCount = 0;//设置动画次数 0 表示无限
    [animationImageView startAnimating];//开始播放动画
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.backgroundColor = [UIColor clearColor];
    hud.customView = animationImageView;
    hud.bezelView.color = [UIColor clearColor];
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.removeFromSuperViewOnHide = YES;
    hud.mode =MBProgressHUDModeCustomView;
    return hud;
}

+ (void)hideHud
{
    [MBProgressHUD hideHUDForView:[AppDelegate appDelegate].window animated:YES];
}

+ (void)hideAllHud
{
    NSMutableArray *huds = [NSMutableArray array];
    NSArray *subviews = [AppDelegate  appDelegate].window.subviews;
    for (UIView *aView in subviews) {
        if ([aView isKindOfClass:[MBProgressHUD class]]) {
            [huds addObject:aView];
        }
    }
    for (MBProgressHUD *hud in huds) {
        hud.removeFromSuperViewOnHide = YES;
        [hud hideAnimated:YES];
    }
}
// 设置IQKeyboardManager参数
- (void)setIQKeyboardManager
{
    // 获取类库的单例变量
    IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager];
    // 控制是否显示键盘上的工具条
    keyboardManager.enableAutoToolbar = NO;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    
    
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    // 隐藏返回文字
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
    
    [AppDelegate showLogin];
    
    // 设置IQKeyboardManager参数
    [self setIQKeyboardManager];
    
#if defined(DEBUG)||defined(_DEBUG)
    // 显示TPS
//    [TYFPSLabel showInStutasBar];
#endif
    
    return YES;
}



- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    return;
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
//    NSInteger count = [[[NIMSDK sharedSDK] conversationManager] allUnreadCount];
//    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:count];
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


// 支持所有iOS系统    // 适配iPhone5暂时注释
//- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
//{
//    BOOL result = [[ThirdLoginShareVerifyManager shareInstance] handleOpenURL:url];
//    return result;
//}
//
//// iOS 9 以上请用这个   // 适配iPhone5暂时注释
//- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options {
//    
//    BOOL result = [[ThirdLoginShareVerifyManager shareInstance] handleOpenURL:url];
//    
//    return result;
//}


//注册
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    
}

//注册失败
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    //Optional
    NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
    // Required, iOS 7 Support,小于ios10.0
}


@end
